// var vConsole = new VConsole();

var app = new Vue({
	el: '#app',
	data: {
		uploaderFront: '',
		uploaderBack: '',
		username: '', //用户姓名
		idNo: '', //身份证号
		checked: false, //是否同意
		addressInfo: {} //地理位置信息
	},
	computed: {
		disabled() {
			if (this.uploaderFront && this.uploaderBack && this.username && this.idNo && this.checked) {
				return false;
			} else {
				return true;
			}
		}
	},
	created() {
		const localData = utils.getItem('step1');
		if (localData) {
			for (let [key, value] of Object.entries(localData)) {
				this[key] = value;
			}
		};
	},
	methods: {
		jump(path, query) {
			utils.jump(path, query);
		},
		uploadPic: function (param) {
			let ref = param === "uploaderFront" ? this.$refs.uploaderFront : this.$refs.uploaderBack;
			ref.click();
		},
		onFileChange: function (param, event) {
			let file = event.target.files[0];
			if (file.size < Math.pow(1024, 2)) {
				this.successFile(file, param);
			} else {
				this.zipImg(file, param);
			}
		},
		successFile(file, param) {
			const reader = new FileReader();
			reader.readAsDataURL(file);
			reader.onload = (result) => {
				this[param] = result.target.result;
				this.$refs[param].value = "";
			};
		},
		zipImg(file, param) {
			utils.zipImg(file, (base64) => {
				this[param] = base64;
				this.$refs[param].value = "";
			})
		},
		checkToggle: function () {
			this.checked = !this.checked;
		},
		goNextStep: function () {
			if (this.disabled) {
				return;
			}
			// 校验姓名，身份证号
			const chineseNameReg = new RegExp(regExpConfig.chineseName);
			const idCardReg = new RegExp(regExpConfig.IDcard)
			if (!chineseNameReg.test(this.username)) {
				this.$toast('请输入正确姓名');
				return;
			}
			if (!idCardReg.test(this.idNo)) {
				this.$toast('请输入正确的身份证号');
				return;
			};
			utils.setItem('step1', this.$data);
			this.jump('register-step2');
		}
	}
});


